let Mock = require('mockjs');
// 用户信息的数据模块
let num = Mock.mock({
  "obj|3": [{
    "id": "@id",
    "username": /[1-9]{6}/,
    "user_type|1": ["注册用户", "已认证用户", "后台分配用户"],
    "key_code": "@string(9)",
    "password": "123456",
    "phone": /1\d{10}/,
    "tel": /1\d{10}/,
    "nickName": "@cname",
    "avatarUrl": "http://127.0.0.1/public/user/0818201911309.jpg",
    "display": ["可用", "禁用"],
    "gender|1": ["女", "男"],
    "birthday": "@date",
    "location": "@city",
    "email": "@email",
    "login_num|1-100": 100,
    "login_ip": "@ip",
    "login_titme": "@datetime",
    "balance|1000-10000": 100,
    "add_time": function () { return this.login_titme },
    //是否是商家认证，大于0就是商家
    "has_company|1": true,
    // 是否是个人认证,大于0就是个人认证 
    "has_personal|1": true,
    // 是否巡检员账号，大于0就是巡检员
    "has_inspector|1": true,
    // 是否绑定了微信，大于0就是已经绑定了
    "has_wechat|1": true,
    // 是否是业务员，1:是，0:否
    "has_ywy|1": true,
  }]
})
let userlist = num.obj
// 添加用户
function adduser (user) {
  user.id = Mock.mock('@id');
  userlist.push(user)
  return user;
}
// 删除用户
function delUser (id) {
  let i = userlist.findIndex((item) => {
    return item.id == id
  })
  return user;
}
// 更新用户
function updateUser (user) {
  let i = userlist.findIndex((item) => {
    return item.id == user.id
  })
  userlist.splice(i,1,user)
  return user;
}
module.exports = {
  userList: num.obj,
  adduser,
  updateUser
}
// exports.adduser